import "package:flutter/material.dart";
import "../type.dart";

// up推荐商品
class DynamicUPRecommendGoodsWidget extends StatelessWidget {
  final List<DynamicUPRecommendGoods> dynamicUPRecommendGoodsList;
  const DynamicUPRecommendGoodsWidget({
    super.key,
    required this.dynamicUPRecommendGoodsList,
  });
  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.only(left: 10, right: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          const Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Icon(
                Icons.shopping_bag_outlined,
                size: 16,
                color: Colors.black38,
              ),
              Padding(
                padding: EdgeInsets.only(left: 4),
                child: Text(
                  'UP主的推荐',
                  style: TextStyle(
                    fontSize: 12,
                    color: Colors.black38,
                  ),
                ),
              )
            ],
          ),
          dynamicUPRecommendGoodsList.length == 1
              ? Stack(
                  alignment: Alignment.bottomRight,
                  children: [
                    Container(
                        padding: const EdgeInsets.fromLTRB(8, 8, 20, 8),
                        margin: const EdgeInsets.only(top: 4, bottom: 4),
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 243, 243, 244),
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Padding(
                              padding: const EdgeInsets.only(right: 8),
                              child: ClipRRect(
                                borderRadius: BorderRadius.circular(4),
                                child: Image.asset(
                                  dynamicUPRecommendGoodsList[0].coverUrl,
                                  width: 64,
                                  height: 64,
                                  fit: BoxFit.cover,
                                ),
                              ),
                            ),
                            Expanded(
                                flex: 1,
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Text(
                                      dynamicUPRecommendGoodsList[0].title,
                                      maxLines: 1,
                                      overflow: TextOverflow.ellipsis,
                                      style: const TextStyle(height: 1.6),
                                    ),
                                    dynamicUPRecommendGoodsList[0].subTitle !=
                                            null
                                        ? Text(
                                            dynamicUPRecommendGoodsList[0]
                                                    .subTitle ??
                                                '',
                                            maxLines: 1,
                                            overflow: TextOverflow.ellipsis,
                                            style: const TextStyle(
                                              color: Colors.black38,
                                              fontSize: 12,
                                            ),
                                          )
                                        : const SizedBox.shrink(),
                                    Text(
                                      '¥ ${dynamicUPRecommendGoodsList[0].price}',
                                      style: const TextStyle(
                                        color:
                                            Color.fromARGB(255, 255, 131, 172),
                                      ),
                                    )
                                  ],
                                )),
                          ],
                        )),
                    const Positioned(
                      right: 8,
                      bottom: 8,
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text(
                            '去看看',
                            style: TextStyle(
                              color: Color.fromARGB(255, 255, 131, 172),
                              fontSize: 13,
                            ),
                          ),
                          Icon(
                            Icons.keyboard_arrow_right_outlined,
                            color: Color.fromARGB(255, 255, 131, 172),
                            size: 16,
                          ),
                        ],
                      ),
                    ),
                  ],
                )
              : Container(
                  height: 64,
                  padding: const EdgeInsets.fromLTRB(8, 8, 20, 8),
                  margin: const EdgeInsets.only(top: 4, bottom: 4),
                  decoration: BoxDecoration(
                    color: const Color.fromARGB(255, 243, 243, 244),
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: ListView.builder(
                    scrollDirection: Axis.horizontal,
                    itemCount: dynamicUPRecommendGoodsList.length,
                    itemBuilder: (context, index) {
                      DynamicUPRecommendGoods item =
                          dynamicUPRecommendGoodsList[index];
                      return ClipRRect(
                        borderRadius: BorderRadius.circular(4),
                        child: Container(
                          width: 50,
                          height: 50,
                          margin: EdgeInsets.only(
                              right: index ==
                                      dynamicUPRecommendGoodsList.length - 1
                                  ? 0
                                  : 4),
                          child: Image.asset(
                            item.coverUrl,
                            fit: BoxFit.cover,
                          ),
                        ),
                      );
                    },
                  ),
                ),
        ],
      ),
    );
  }
}
